package main

import (
	"fmt"
	// "github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	// "log"
	// "net/http"
	"shi_project/main/communicate"
	"shi_project/main/config"
	"shi_project/main/email"
	"shi_project/main/handler"
	"shi_project/main/middle"
	"shi_project/main/signal"
	"shi_project/main/ws"
)

// 如何运行时想修改Env的值 go run -ldflags "-X 'main.Env=pro'" main.go
// var Env = "pro"

func main() {
	fmt.Println("config.Env=", config.Env)
	// go func() {
	// 	http.HandleFunc("/", ws.Chating)
	// 	if config.Env == "dev" {
	// 		log.Fatal(http.ListenAndServe("localhost:8089", nil))
	// 	} else {
	// 		log.Fatal(http.ListenAndServeTLS(":8089", config.CERT_PEM, config.CERT_KEY, nil))
	// 	}
	// }()

	router := gin.New()
	if config.Env == "dev" {
		// router.Use(middle.All(), cors.Default())
		fmt.Println("环境变量：", config.Env)
		router.Use(middle.All())
	}
	router.POST("/login", handler.Login)
	router.GET("/ws", func(c *gin.Context) {
		ws.Chating(c.Writer, c.Request)
	})
	router.GET("/signal", func(c *gin.Context) {
		signal.Home(c.Writer, c.Request)
	})
	v1 := router.Group("v1").Use(middle.V1())
	// v1 := router.Group("v1").Use()
	// v1.GET("/get", handler.Get)
	router.GET("/get", handler.Get) //临时测试接口

	v1.GET("/roles", handler.Roles)
	v1.POST("/roles", handler.AddRoles)
	v1.PUT("/roles", handler.PutRoles)
	v1.DELETE("/roles", handler.DeleteRoles)

	v1.GET("/users", handler.Users)
	v1.POST("/user", handler.AddUser)
	v1.PUT("/user", handler.PutUser)
	v1.DELETE("/user", handler.DeleteUser)

	v1.GET("/permission", handler.PermissionList)
	v1.POST("/permission", handler.AddPermissionList)
	v1.PUT("/permission", handler.PutPermissionList)
	v1.DELETE("/permission", handler.DeletePermissionList)

	v1.DELETE("/rolePermission", handler.DeleteRolePermissionList)

	v1.GET("/currentUser", handler.CurrentUser)

	v1.POST("/uploads", handler.Uploads)
	v1.GET("/music", handler.Music)
	v1.POST("/outLogin", handler.OutLogin)
	v1.GET("/chatLog", communicate.ChatLog)

	v1.POST("/massEmail", email.PostEmail)

	router.Run(":8088")
}
